import socket
import sys

#create a udp socket
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

#bind the socket to the port.
SERVERaddr = ('localhost',10000)
print('开始监听于{}主机，端口{}'.format(*SERVERaddr))
sock.bind(SERVERaddr)

while True:
    #等待连接
    print('等待数据报信息...')
    data,addr = sock.recvfrom(4096)
    print('有{}比特信息，来自于{}主机。'.format(len(data),str(addr)))
    print(data)

    if data:
        sent = sock.sendto(data,addr)
        print('回送{}比特消息，往{}主机。'.format(
            sent,addr))



